package main

import (
	"flag"
	"fmt"
	"git.oschina.net/mingyiyi72/mqtt"
	proto "github.com/huin/mqtt"
	"net"
)

const (
	DEFAULT_HOST = "119.29.7.247:1883"
	DEFAULT_USER = "ping_user_cym"
)

func main() {
	host := flag.String("host", DEFAULT_HOST, "mqtt 服务器密码")
	user := flag.String("user", DEFAULT_USER, "mqtt user")
	flag.Parse()

	conn, err := net.Dial("tcp", *host)
	if err != nil {
		fmt.Println(err)
		return
	}
	mqttClient := mqtt.NewClientConn(conn)

	err = mqttClient.Connect(*user, "")
	if err != nil {
		fmt.Println(err)
		return
	}

	ack := mqttClient.Subscribe([]proto.TopicQos{
		proto.TopicQos{Qos: 0, Topic: "ping_test"},
	})
	if 0 != ack.Header.QosLevel {
		fmt.Println("subscribe error ")
		return
	}

	fmt.Println("mqtt_succ")
}
